package jmine.tec.web.wicket.pages.example.report;

import java.util.List;

import jmine.tec.report.api.Report;
import jmine.tec.report.base.AbstractReportCreator;
import jmine.tec.report.impl.ReportBuilder;
import jmine.tec.report.impl.table.ReportTableBuilder;
import jmine.tec.utils.Tuple;
import jmine.tec.web.wicket.dao.WebTestEntityDAO;
import jmine.tec.web.wicket.domain.WebTestEntity;

/**
 * Exemplo de report creator.
 * 
 * @author Rafael Volpato
 * @date Nov 10, 2011
 */
public class ReportExampleCreator extends AbstractReportCreator<ReportExampleParameter> {

    /**
     * Construtor.
     */
    public ReportExampleCreator() {
        super(ReportExampleParameter.class);
    }

    /**
     * {@inheritDoc}
     */
    public String getCreatorKey() {
        return "key";
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected List<Tuple<String, Report>> doCreateReports(ReportExampleParameter parameter) {
        ReportBuilder reportBuilder =
                new ReportBuilder("Exemplo de relatório da entidade 'WebTestEntity'",
                        this.getFileName("Relatorio WebTestEntity", parameter));

        // Configurando HEADER
        if (parameter.getMnemonico() != null) {
            reportBuilder.addHeaderStringParameter("mnemonico", "Cadastro", parameter.getMnemonico());
        }

        if (parameter.getData() != null) {
            reportBuilder.addHeaderDateParameter("data", "Data", parameter.getData());
        }

        // Adicionando Tabelas
        WebTestEntityDAO dao = this.getController().getDAOFactory().getDAOByClass(WebTestEntityDAO.class);
        List<WebTestEntity> result = dao.findByMnemonicoData(parameter.getMnemonico(), parameter.getData());

        ReportTableBuilder<WebTestEntity> tableBuilder = reportBuilder.createTableBuilder(WebTestEntity.class, "pesquisa");
        tableBuilder.setRecords(result);
        tableBuilder.addStringColumn("nome", "Nome", "nome");
        tableBuilder.addStringColumn("mnemonico", "Mnemônico", "mnemonico");
        tableBuilder.addDateColumn("data", "Data", "data");
        tableBuilder.addNumberColumn("valor", "Valor", "valor", 2);
        tableBuilder.close();

        return this.pack("Relatório WebTestEntity", parameter, reportBuilder.createReport());
    }
}